function bgk_scaleup
%
% Rescales BGK solution to double number of modes.
%

jz=128;  jv=1024

fname_in   = 'a_rc1_dt001.dfu.0005.00'
fname_out  = 'b_rc1_dt001.dfu.0000.00'
fname_img1 = 'b_rc1_dt001_re_0000.png';
fname_img2 = 'b_rc1_dt001_im_0000.png';
fname_img3 = 'b_rc1_dt001_sp_0000.png';

%---------------------------------------------------------

  fid = fopen(fname_in, 'rb');
  dfu = fread(fid, jv*jz*2, 'double');
  fclose(fid);

  dfu = reshape(dfu, 2, jv,jz);

  f = dfu(1,:,:) + i*dfu(2,:,:);

  fmax_in = max(max(abs(f)))


  ff1  =  ifftn(f);
  ff2  =  zeros(2*jv,2*jz);
  ff2(jv/2+1:jv/2+jv, jz/2+1:jz/2+jz) = ifftshift(ff1);
  ff2  = fftshift(ff2);

  f = fftn(ff2);  

  fmax_out = max(max(abs(f)))


  % figure(1); imagesc(flipud(log(abs(fftshift(ff2)))), [log(1.e-19), log(1e-3)]);
  % figure(2); imagesc(flipud(dfu), [-0.01,0.01] );   axis('equal', 'tics', 'off');

  one_image(real(f), -0.01, 0.01, fname_img1);
  one_image(imag(f), -0.01, 0.01, fname_img2);
  one_image(log(abs(fftshift(ff2))), log(1.e-19), log(1e-3), fname_img3);

  dfu = zeros(2, 2*jv, 2*jz);
  dfu(1,:,:) = real(f);
  dfu(2,:,:) = imag(f);

  fid = fopen(fname_out, 'wb');
  fwrite(fid, dfu, 'double');
  fclose(fid);

end

 %---------------------------------------------------------


function one_image(a, amin, amax, fname)
%
%   one_image(a, amin, amax, fname)
%

  a = max(a,amin);
  a = min(a,amax); 

  map = colormap(jet(256));
  %map = colormap(gray(256));

  sc   =  uint8(255*(a-amin)/(amax-amin)) + 1;
  imwrite(flipud(sc), map, fname);
  %saveimage([fname, '.ppm'], flipud(sc), 'ppm', map);

  %imagesc(flipud(a));

end
 
%---------------------------------------------------------

